/*
 * MainNavigationBar.fx
 *
 * Created on Feb 25, 2010, 2:40:51 PM
 */
package com.gpsbuddy.navigation;

import javafx.scene.CustomNode;
import javafx.scene.Node;
import javafx.scene.Group;
import com.gpsbuddy.graphics.closeUI;
import javafx.scene.shape.Rectangle;
import javafx.scene.paint.Color;
import javafx.scene.paint.LinearGradient;
import javafx.scene.paint.Stop;
import com.gpsbuddy.utils.Utils;
import javafx.scene.text.Text;
import com.gpsbuddy.graphics.homeUI;
import javafx.scene.layout.HBox;
import javafx.geometry.HPos;
import javafx.geometry.VPos;
import com.gpsbuddy.main.Main;
import com.gpsbuddy.main.Enviroment;

/**
 * @author jonycus
 */
public class MainStatusBar extends CustomNode {

    public var env:Enviroment;

    public var width: Number;
    public var height: Number;
    public var barHeight:Number;
    var closeButton = closeUI {
                }
    var barBackGround = Rectangle {
                width: getWidth();
                height: bind barHeight;
                fill: LinearGradient { proportional: false startX: 300.00 startY: 30.00 endX: 300.00 endY: 0.00 stops: [
                        Stop { offset: 0.000 color: Color.WHITE },
                        Stop { offset: 1.000 color: Color.rgb(240, 240, 240) },
                    ] }
                stroke: Color.DARKGRAY;
            }
    public var statusText: String = bind env.statusText;
    var status = Text {
                layoutY: 16;
                layoutX: 4;
                content: bind statusText;
            }
    var homeButton = homeUI {
            visible:  Main.renderHomeButton;
            override def onMouseClicked = function (event) {
                Main.switchToFrontPage();
            }

                }
    var buttonsBox = HBox {
                layoutX: getWidth() - 60;
                layoutY: 4;
                hpos: HPos.CENTER;
                content: [homeButton, closeButton];
                vpos: VPos.CENTER;
                nodeVPos: VPos.CENTER;
                spacing: 10
            }
    var group = Group {
                layoutY: getLayoutY()
                content: [barBackGround, buttonsBox, status]
            }

    override protected function create(): Node {
        return group;
    }

    function getLayoutY(): Number {
        if (Utils.isMobile) {
            return height - barBackGround.height;
            } else {
            return height - 2 * barBackGround.height - 5;
            }
    }

    function getWidth(): Number {
        if (Utils.isMobile) {
            return width;
            } else {
            return width - 15;
            }
    }

}
